import { getToken, setToken } from '@/utils/auth'
import { login } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, payload) {
      state.token = payload
      setToken(payload)
    }
  },
  actions: {
    async postToken(context, payload) {
      const res = await login(payload)
      context.commit('setToken', res.data)
      return res
    }

  },
  getters: {}

}
